home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / libs / unixlib.lha / unix / src / tempnam.c < prev    next >
C/C++ Source or Header  |  1996-02-11  |  589b  |  31 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <errno.h>
  5.  
  6. char *
  7. tempnam(const char *tmpdir, const char *prefix)
  8. {
  9.     char *ptr, *tmp, buffer[L_tmpnam + 1];
  10.     int extra = 1;
  11.  
  12.     if ((ptr = strchr(tmpnam(buffer), ':')) != NULL)
  13.         ++ptr;
  14.     else
  15.         ptr = buffer;
  16.     
  17.     if (tmpdir[strlen(tmpdir)-1] != ':' && tmpdir[strlen(tmpdir)-1] != '/')
  18.         extra = 2;
  19.     tmp = malloc(strlen(tmpdir)+strlen(prefix)+strlen(ptr)+extra);
  20.     if (!tmp) {
  21.         errno = ENOMEM;
  22.         return(0);
  23.     }
  24.     strcpy(tmp, tmpdir);
  25.     if (extra == 2)
  26.         strcat(tmp, "/");
  27.     strcat(tmp, prefix);
  28.     strcat(tmp, ptr);
  29.     return(tmp);
  30. }
  31.